<?php

	namespace Phptricks\system\library\database;

	/**
	 * Description of database
	 *
	 * @author Sammy Guergachi <sguergachi at gmail.com>
	 */
	use Phptricks\system\core\library\library;
	use Phptricks\system\library\PhptricksExceptions\PhptricksExceptions as Exc;

	class database extends \PDO implements library{

		private static $_instance = null;
		public static $_config_data;
		public $_config;
		private $_dsn = '';
		private $_dbdriver;
		private $_host_name;
		private $_username;
		private $_password;
		private $_database;
		private $_port;
		private $_char_set;
		private $_default_collation;
		public $_query_limit;
		public $_prefix;
		public $_list_query = array();
		public $_order_by;
		public $fatch_mode = array(
			'FETCH_LAZY' => '1',
			'FETCH_ASSOC' => '2',
			'FETCH_NUM' => '3',
			'FETCH_BOTH' => '4',
			'FETCH_OBJ' => '5',
			'FETCH_BOUND' => '6',
			'FETCH_COLUMN' => '7',
			'FETCH_CLASS' => '8',
			'FETCH_INTO' => '9',
			'FETCH_FUNC' => '10',
			'FETCH_NAMED' => '11',
			'FETCH_KEY_PAIR' => '12',
			'FETCH_GROUP' => '65536',
			'FETCH_UNIQUE' => '196608',
			'FETCH_CLASSTYPE' => '262144',
			'FETCH_SERIALIZE' => '524288',
			'FETCH_PROPS_LATE' => '1048576',
		);

		public function __construct(){
			try {
				$this->_config = self::$_config_data;
				$this->_dbdriver = $this->_config->dbdriver;
				$this->_host_name = $this->_config->hostname;
				$this->_username = $this->_config->username;
				$this->_password = $this->_config->password;
				$this->_database = $this->_config->database;
				$this->_port = $this->_config->port;
				$this->_char_set = $this->_config->char_set;
				$this->_default_collation = $this->_config->default_collation;
				$this->_prefix = $this->_config->table_prefix;
				$this->_query_limit = $this->_config->query_limit;
				$this->_dsn = $this->_dbdriver . ':host=' . $this->_host_name . ';dbname=' . $this->_database . ';';

				parent::__construct($this->_dsn, $this->_username, $this->_password);
				$this->setAttribute(parent::ATTR_DEFAULT_FETCH_MODE, parent::FETCH_ASSOC);
			} catch (\PDOException $e) {
				throw new Exc($e->getTraceAsString());
			}
		}

		public static function set_configretion($param){
			
		}

		public static function getinstance(){
			if (self::$_instance === null) {
				self::$_instance = new \Phptricks\system\library\database\database();
			}
			return self::$_instance;
		}

		public static function _initialize_configuration($config_data){
			self::$_config_data = $config_data;
		}

	}
	